<template>
	<view class="content">
		<headerSpaceBetweenVue>
			<template #icon>
				<text @click="changePwd()">修改</text>
			</template>
			<template #title>修改密码</template>
		</headerSpaceBetweenVue>
		<view class="container">
			<view class="input-group">
				<text class="input-label">原密码</text>
				<input v-model="formData.oldPassword" class="password-input" type="password" placeholder="原密码"
					placeholder-class="placeholder" />
			</view>

			<view class="input-group">
				<text class="input-label">新密码</text>
				<input v-model="formData.newPassword" class="password-input" type="password" placeholder="新密码"
					placeholder-class="placeholder" />
			</view>

			<view class="input-group">
				<text class="input-label">确认新密码</text>
				<input v-model="formData.confirmPassword" class="password-input" type="password" placeholder="确认新密码"
					placeholder-class="placeholder" />
			</view>

			<view class="requirements-section">
				<text class="requirements-title">密码要求:</text>
				<view class="requirement-item">
					<view class="blue-dot"></view>
					<text class="requirement-text">长度为5-12个字符</text>
				</view>
				<view class="requirement-item">
					<view class="blue-dot"></view>
					<text class="requirement-text">必须包含字母和数字</text>
				</view>
				<view class="requirement-item">
					<view class="blue-dot"></view>
					<text class="requirement-text">区分大小写</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue';
	import {
		apiChangePwd
	} from '@/api/apis';
	import headerSpaceBetweenVue from '@/components/header-space-between/header-space-between.vue';
	let formData = ref({
		oldPassword : '',
		newPassword : ''
	})
	const tip = (ctn) => {
		uni.showToast({
			title: ctn,
			icon: "none"
		})
	}
	const changePwd = async () => {
		if (formData.value.oldPassword == "" || formData.value.newPassword == "") {
			tip("请将信息输入完整")
			return
		}
		if (formData.value.confirmPassword != formData.value.newPassword) {
			tip("两次密码输入不一致")
			return
		}
		await apiChangePwd(formData.value).then(res => {
			if (res.code == 200) {
				tip("修改成功")
			} else {
				tip(res.msg)
			}
		})

	}
</script>

<style lang="scss" scoped>
	.content {
		position: relative;
		padding: 20rpx;
		padding-top: calc(var(--status-bar-height) + 100rpx);

		.container {
			background-color: #FFFFFF;
			padding: 40rpx;
			height: 100vh;
			display: flex;
			flex-direction: column;
		}

		.input-group {
			margin-bottom: 50rpx;
			display: flex;
			flex-direction: column;
		}

		.input-label {
			font-size: 32rpx;
			color: #000000;
			margin-bottom: 20rpx;
			font-weight: normal;
		}

		.password-input {
			height: 80rpx;
			border: 1rpx solid #e5e5e5;
			border-radius: 8rpx;
			padding: 0 25rpx;
			font-size: 32rpx;
		}

		.placeholder {
			color: #CCCCCC;
		}

		.requirements-section {
			margin-top: 30rpx;
		}

		.requirements-title {
			font-size: 32rpx;
			color: #000000;
			margin-bottom: 20rpx;
			display: block;
		}

		.requirement-item {
			display: flex;
			align-items: center;
			margin-bottom: 20rpx;
		}

		.blue-dot {
			width: 12rpx;
			height: 12rpx;
			border-radius: 50%;
			background-color: $theme-color;
			margin-right: 15rpx;
		}

		.requirement-text {
			font-size: 28rpx;
			color: #000000;
		}
	}
</style>